<?php
namespace app\api\controller;

class Purchasedata
{
   //Echarts图表数据
   public function index() {
       $Purchasedata = model('purchasedata')->field('number')->order('number','desc')->limit('5')->select()->toArray();
       $classdata = model('cate')->alias('a')->join('purchasedata w','a.id = w.class_id','RIGHT')->field('cate_name')->order('w.number desc' )->limit('5')->select()->toArray();
       $Purchasedatas = sliceArray($Purchasedata,5,1);
       $data = ['data'=>$Purchasedatas, 'classname'=>$classdata, 'status'=> 0];
       return json($data);
   }
   //立即购买 number加一
   public function number($class_id) {
          $Purchasedata = model('purchasedata')->field('number')->where('class_id', $class_id)->select()->toArray();
          $xg = model('purchasedata')->where('class_id', $class_id)->data(['number' => $Purchasedata[0]['number'] + 1])->update();
          if($xg) {
             echo '成功';
          }else {
             echo '失败';
          }
      }
}
